home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows 95 API Bible
/
Windows 95 API Bible 3 Disc Set.iso
/
Win32 API Bible Book 1 of 3.iso
/
chapte18
/
ex4.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-12-27
|
4KB
|
123 lines
#include <genstub.c>
LRESULT CALLBACK WndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static UINT wClipFormat; // registered clipboard format
switch (uMsg) /* process windows messages */
{
case WM_CREATE:
/* register the format "SPECIAL" when the window is created */
/* multiple instances of the program will only register the format once */
wClipFormat = RegisterClipboardFormat( "SPECIAL" );
/* set clipboard for delayed rendering*/
OpenClipboard( hWnd );
EmptyClipboard( );
SetClipboardData( CF_TEXT, 0 );
if (wClipFormat)
SetClipboardData( wClipFormat, 0 );
CloseClipboard( );
break ;
case WM_RENDERALLFORMATS:
case WM_RENDERFORMAT:
{ /* delayed rendering of clipboard formats - now put data in clipboard */
HANDLE hMem;
LPVOID lpData;
OpenClipboard( hWnd );
EmptyClipboard( );
/* render CF_TEXT format */
hMem = GlobalAlloc( GHND, 64 );
lpData = GlobalLock( hMem );
lstrcpy( lpData, "Text In Clipboard" );
GlobalUnlock( hMem );
SetClipboardData( CF_TEXT, hMem );
/* render format "SPECIAL" */
if (wClipFormat)
{
hMem = GlobalAlloc( GHND, 64 );
lpData = GlobalLock( hMem );
lstrcpy( lpData, "Private format SPECIAL data in clipboard" );
GlobalUnlock( hMem );
SetClipboardData( wClipFormat, hMem );
}
CloseClipboard( );
}
break ;
case WM_PAINT:
{
HANDLE hMem;
LPVOID lpData;
PAINTSTRUCT ps;
char cBuf[128];
UINT wPriorityList[ 2 ]; // list of clipboard formats to search for
BeginPaint( hWnd, &ps );
/* check state of CF_TEXT first */
OpenClipboard( hWnd );
hMem = GetClipboardData( CF_TEXT );
if ( hMem )
{
lpData = GlobalLock( hMem );
TextOut( ps.hdc, 10, 10, cBuf, wsprintf( cBuf,
"CF_TEXT contains: %s", lpData ) ) ;
GlobalUnlock( hMem );
}
CloseClipboard( );
/* now check state of SPECIAL format */
OpenClipboard( hWnd );
wPriorityList[ 0 ] = wClipFormat ;
wPriorityList[ 1 ] = CF_TEXT ;
if ( wClipFormat = GetPriorityClipboardFormat( wPriorityList, 2 ) )
{
hMem = GetClipboardData( wClipFormat );
lpData = GlobalLock( hMem );
TextOut( ps.hdc, 10, 30, cBuf, wsprintf( cBuf,
"Special CB Format contains: %s", lpData ) );
GlobalUnlock( hMem );
}
else {
TextOut( ps.hdc, 10, 30, cBuf, wsprintf( cBuf,
"Special CB Format not available." ) ) ;
}
CloseClipboard( );
EndPaint( hWnd, &ps );
}
break ;
case WM_COMMAND:
switch (wParam)
{
case IDM_TEST: /* provoke paint to show state of clipboard formats */
InvalidateRect( hWnd, NULL, TRUE );
break;
case IDM_EXIT:
DestroyWindow( hWnd );
break;
#include <aboutopt.c>
}
break;
#include <rbutton.c>
case WM_DESTROY: /* stop application */
PostQuitMessage( 0 );
break;
default: /* default windows message processing */
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
return (0L) ;
}
#include <about.c>